package com.ruoyi.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.Kind;
import com.ruoyi.service.IKindService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 审批类型Controller
 *
 * @author ya
 * @date 2025-01-18
 */
@RestController
@RequestMapping("/kind/kind")
public class KindController extends BaseController
{
    @Autowired
    private IKindService kindService;

    /**
     * 查询审批类型列表
     */
//    @PreAuthorize("@ss.hasPermi('kind:kind:list')")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(Kind kind)
    {
        startPage();
        List<Kind> list = kindService.selectKindList(kind);
        return getDataTable(list);
    }

    /**
     * 导出审批类型列表
     */
//    @PreAuthorize("@ss.hasPermi('kind:kind:export')")
    @Log(title = "审批类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Kind kind)
    {
        List<Kind> list = kindService.selectKindList(kind);
        ExcelUtil<Kind> util = new ExcelUtil<Kind>(Kind.class);
        util.exportExcel(response, list, "审批类型数据");
    }

    /**
     * 获取审批类型详细信息
     */
//    @PreAuthorize("@ss.hasPermi('kind:kind:query')")
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(kindService.selectKindById(id));
    }

    /**
     * 新增审批类型
     */
    @PreAuthorize("@ss.hasPermi('kind:kind:add')")
    @Log(title = "审批类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Kind kind)
    {
        return toAjax(kindService.insertKind(kind));
    }

    /**
     * 修改审批类型
     */
    @PreAuthorize("@ss.hasPermi('kind:kind:edit')")
    @Log(title = "审批类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Kind kind)
    {
        return toAjax(kindService.updateKind(kind));
    }

    /**
     * 删除审批类型
     */
    @PreAuthorize("@ss.hasPermi('kind:kind:remove')")
    @Log(title = "审批类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(kindService.deleteKindByIds(ids));
    }
}
